package org.jeecg.modules.demo.wz.utils;

import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.Date;

public class WeekUtils {
    private WeekUtils(){
    }

    public static String getLastWeek(Integer day){
        LocalDateTime now = LocalDateTime.now();
        String weekDay=now.getDayOfWeek().toString();
        int num=0;
        switch (weekDay)
        {
            case "MONDAY":
                num=1;
                break;
            case "TUESDAY":
                num=2;
                break;
            case "WEDNESDAY":
                num=3;
                break;
            case "THURSDAY":
                num=4;
                break;
            case "FRIDAY":
                num=5;
                break;
            case "SATURDAY":
                num=6;
                break;
            case "SUNDAY":
                num=7;
                break;
            default:
                System.out.println("数据错误");
        }
        long l = Instant.now().toEpochMilli() - 1000 * 60 * 60 * 24 * (num+day);
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(new Date(l));
    }
}
